<?php

namespace App\Services\YunXinCloud;


use App\Constants\CodeData;
use App\Exception\MessageException;
use App\Utils\LoggerUtil;
use Throwable;
use function Hyperf\Config\config;

class WyyChatRoomMessageClient extends WyyClient
{

    /**
     * Note - 发送自定义聊天室消息
     * DateTime 2024/9/4 11:48
     * User Admin
     * @param $roomId
     * @param $fromAccid
     * @param $message
     * @return true
     */
    public function sendCustomRoomMsg($roomId, $message, $fromAccid)
    {
        $url = "/chatroom/sendMsg.action";
        $args = [
            "roomid" => $roomId,
            "msgId" => uniqid(),
            "fromAccid" => strval($fromAccid),
            "msgType" => 100,
            "ext" => $message
        ];
        LoggerUtil::write("send_room_msg", $args, 'args');
        $result = $this->postDataCurl($url, $args);
        LoggerUtil::write("send_room_msg", $result, "result");
        if ($result["code"] !== 200 || !isset($result["desc"]["msgid_client"])) {
            throw new MessageException($result['desc'], CodeData::NEED_TIPS, [], false);
        }
        return true;
    }

}